package com.yunkaweilai.android.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.github.lazylibrary.util.StringUtils;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.model.print.MemberRechargePrintModel;
import com.yunkaweilai.android.model.print.ReceivablesPrintModel;

/**
 * 查看会员卡内剩余dialog
 */

public class MemberCardDialog extends Dialog {

    private String member_id;
    private TextView mTvName;
    private TextView mTvLevel;
    private TextView mTvMoney;
    private TextView mTvPhone;
    private TextView mTvNumber;
    private TextView mTvScore;
    private TextView mTvJici;
    private TextView mTvJishi;
    private TextView mTvBsd;
    private LinearLayout imageView;
    private ImageView imageViewNothing;
    private LinearLayout linearLayout;
    private ScrollView ScrollView;
    private ReceivablesPrintModel.DataBean.MemberInfoBean memberInfoModel;
    private MemberRechargePrintModel.DataBean.MemberInfoBean memberInfoModel1;
    private String type;
    public static String TYPE_1 = "XIAOFEI";
    public static String TYPE_2 = "CHONGZHI";

    public MemberCardDialog(Context context, ReceivablesPrintModel.DataBean.MemberInfoBean memberInfoBean, String type) {
        super(context, R.style.dialog);
        this.member_id = member_id;
        this.memberInfoModel = memberInfoBean;
        this.type = type;
    }

    public MemberCardDialog(Context context, MemberRechargePrintModel.DataBean.MemberInfoBean memberInfoBean, String type) {
        super(context, R.style.dialog);
        this.member_id = member_id;
        this.memberInfoModel1 = memberInfoBean;
        this.type = type;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_member_card_have);
        mTvName = findViewById(R.id.id_tv_name);
        mTvLevel = findViewById(R.id.id_tv_level);
        mTvMoney = findViewById(R.id.id_tv_money);
        mTvPhone = findViewById(R.id.id_tv_phone);
        mTvNumber = findViewById(R.id.id_tv_number);
        mTvScore = findViewById(R.id.id_tv_score);
        mTvJici = findViewById(R.id.id_tv_jici);
        mTvJishi = findViewById(R.id.id_tv_jishi);
        mTvBsd = findViewById(R.id.id_tv_bsd);
        imageView = findViewById(R.id.id_img_close);
        linearLayout = findViewById(R.id.line_nothing);
        imageViewNothing = findViewById(R.id.img_nothing);
        ScrollView = findViewById(R.id.scroll_k);
        if (type.equals(TYPE_1)) {
            initView();
        } else if (type.equals(TYPE_2)) {
            initView1();
        }
    }


    //消费时的view
    private void initView() {
        mTvName.setText(memberInfoModel.getMember_name());
        mTvLevel.setText(memberInfoModel.getLevel_name());
        mTvMoney.setText(memberInfoModel.getMember_price());
        mTvPhone.setText(memberInfoModel.getMember_tel());
        mTvNumber.setText(memberInfoModel.getCard_no());
        mTvScore.setText(memberInfoModel.getMember_points());
        mTvJici.setText(memberInfoModel.getMember_jici());
        mTvJishi.setText(memberInfoModel.getMember_jishi());
        mTvBsd.setText(memberInfoModel.getMember_baoshiduan());
        if (StringUtils.isEmpty(memberInfoModel.getMember_jici()) && StringUtils.isEmpty(memberInfoModel.getMember_jishi())  && StringUtils.isEmpty(memberInfoModel.getMember_baoshiduan()) ) {
            ScrollView.setVisibility(View.GONE);
            linearLayout.setVisibility(View.VISIBLE);
        } else {
            if (StringUtils.isEmpty(memberInfoModel.getMember_jici()) ) {
                mTvJici.setVisibility(View.GONE);
            } else {
                mTvJici.setText(Html.fromHtml("<font color='#555555'>" + "剩余计次：" + "</font>" + memberInfoModel.getMember_jici()));
            }
            if (StringUtils.isEmpty(memberInfoModel.getMember_jishi()) ) {
                mTvJishi.setVisibility(View.GONE);
            } else {
                mTvJishi.setText(Html.fromHtml("<font color='#555555'>" + "剩余计时：" + "</font>" + memberInfoModel.getMember_jishi()));
            }
            if (StringUtils.isEmpty(memberInfoModel.getMember_baoshiduan()) ) {
                mTvBsd.setVisibility(View.GONE);
            } else {
                mTvBsd.setText(Html.fromHtml("<font color='#555555'>" + "剩余包时段：" + "</font>" + memberInfoModel.getMember_baoshiduan()));
            }
        }
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }

    //充值时的view
    private void initView1() {
        mTvName.setText(memberInfoModel1.getMember_name());
        mTvLevel.setText(memberInfoModel1.getLevel_name());
        mTvMoney.setText(memberInfoModel1.getMember_price());
        mTvPhone.setText(memberInfoModel1.getMember_tel());
        mTvNumber.setText(memberInfoModel1.getCard_no());
        mTvScore.setText(memberInfoModel1.getMember_points());
        if (StringUtils.isEmpty(memberInfoModel1.getMember_jici()) && StringUtils.isEmpty(memberInfoModel1.getMember_jishi())  && StringUtils.isEmpty(memberInfoModel1.getMember_baoshiduan()) ) {
            ScrollView.setVisibility(View.GONE);
            linearLayout.setVisibility(View.VISIBLE);
        } else {
            if (StringUtils.isEmpty(memberInfoModel1.getMember_jici()) ) {
                mTvJici.setVisibility(View.GONE);
            } else {
                mTvJici.setText(Html.fromHtml("<font color='#555555'>" + "剩余计次：" + "</font>" + memberInfoModel1.getMember_jici()));
            }
            if (StringUtils.isEmpty(memberInfoModel1.getMember_jishi()) ) {
                mTvJishi.setVisibility(View.GONE);
            } else {
                mTvJishi.setText(Html.fromHtml("<font color='#555555'>" + "剩余计时：" + "</font>" + memberInfoModel1.getMember_jishi()));
            }
            if (StringUtils.isEmpty(memberInfoModel1.getMember_baoshiduan()) ) {
                mTvBsd.setVisibility(View.GONE);
            } else {
                mTvBsd.setText(Html.fromHtml("<font color='#555555'>" + "剩余包时段：" + "</font>" + memberInfoModel1.getMember_baoshiduan()));
            }
        }
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }
}
